<template>
  <div>
    <input type="text" class="content" @keyup.enter="add" placeholder="请输入你的任务名称，按回车键确认" v-model="title">
  </div>
</template>

<script>
import {nanoid} from 'nanoid';
export default {
  name: "MyHeader",
  data(){
    return{
      title:''
    }
  },
  methods:{
    add(){
      if(!this.title.trim()) return alert('输入的值不能为空！');
      const todoObj={
        id:nanoid(),
        title:this.title,
        done:false
      };
      this.$emit("addTodo",todoObj)
      this.title=''
    }

  }
}
</script>

<style scoped lang="less">
div{
  width: 90%;
  height: 8%;
  background-color: #ffffff;
  box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.1),-1px -1px 5px 1px rgba(0,0,0,0.1);
  margin: 10px auto 2px auto;
  display: flex;
  .content{
    width: 95%;
    height: 80%;
    font-size: 25px;
    outline: none;
    display: block;
    margin: auto;
    justify-content: center;
    align-self: center;
    border: none;
  }
}
</style>
